package demo;

public class Animal {
    protected String name;
    public Animal(String name){
        this.name = name;
    }
}


interface IFlying{
    void fly();
}

interface IRunning{
    void run();
}

interface ISwimming{
    void swim();
}

//接下来我们创建几个具体的动物
class Cat extends Animal implements IRunning{
    public Cat(String name){
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name + "正在用四条腿跑");
    }
}


class Fish extends Animal implements ISwimming{
    public Fish(String name){
        super(name);
    }

    @Override
    public void swim() {
        System.out.println(this.name + "正在用尾巴游泳");
    }
}




class Dask extends Animal implements IRunning,ISwimming,IFlying{
    public Dask(String name){
        super(name);
    }

    @Override
    public void fly() {
        System.out.println(this.name + "飞");
    }

    @Override
    public void run() {
        System.out.println(this.name + "跑");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "游泳");
    }
}



class Test{
    //例如 现在实现一个方法，叫“散步”
    public static void walk(IRunning running){
        running.run();
    }

    public static void main(String[] args) {
        //在这个walk方法内部，我们并不关注到底是哪种动物，只要参数是会跑的就行
        Cat cat = new Cat("小猫");
        walk(cat);
       Robot robot = new Robot("机器人");
        walk(robot);
    }
}


//甚至参数可以不要“动物”，只要会跑
class Robot implements IRunning{
    private String name;
    public Robot(String name){
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println(this.name + "正在用轮子跑");
    }
}


